library(gt)
#gc()
load('results/survey/main-survey-results-weights.Rdata')
#load('results/survey/pid-states-survey-models-weights.Rdata')
#rm(list=ls()[!(grepl('SpExp', ls()))])
#gc()
source('../../Jake_R_functions/felm-summary-table.R')
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7'
)
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7'
)
l = list(w10DemSpExp, w10RepSpExp, w35DemSpExp, w35RepSpExp, w39DemSpExp, w39RepSpExp)
names(l) = c('(1)', '(2)','(3)', '(4)','(5)', '(6)')
tab1 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l), fmt =3)
tab1 %>%
# column labels
tab_spanner(label = 'Neighborhood PID', columns = 2:3) %>%
tab_spanner(label = 'Contact Dem Neighbors', columns = 4) %>%
tab_spanner(label = 'Contact Rep Neighbors', columns = 5) %>%
tab_spanner(label = 'Dem - Rep Therm', columns = 6:7)
tab1 %>%
# column labels
tab_spanner(label = 'Neighborhood PID', columns = 2:3) %>%
tab_spanner(label = 'Contact Dem Neighbors', columns = 4) %>%
tab_spanner(label = 'Contact Rep Neighbors', columns = 5) %>%
tab_spanner(label = 'Dem - Rep Therm', columns = 6:7)%>%
as_latex()%>%
write_file('tables/main-survey-results-weights-1.tex')
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7')
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7')
l = list(w40DemSpExp,w40RepSpExp,w16DemSpExp,w16RepSpExp, w17DemSpExp,w17RepSpExp,w18DemSpExp,w18RepSpExp)
names(l) = c('(1)','(2)', '(3)', '(4)','(5)','(6)', '(7)', '(8)')
tab2 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l),
fmt=3)
tab2 %>%
# column labels
tab_spanner(label = 'Share PID', columns = 2:3) %>%
tab_spanner(label = 'Bumper Sticker', columns = 4:5) %>%
tab_spanner(label = 'Yard Sign', columns = 6:7) %>%
tab_spanner(label = 'Clothing', columns = 8:9)
tab2 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l),
fmt=3)
tab2 %>%
# column labels
tab_spanner(label = 'Share PID', columns = 2:3) %>%
tab_spanner(label = 'Bumper Sticker', columns = 4:5) %>%
tab_spanner(label = 'Yard Sign', columns = 6:7) %>%
tab_spanner(label = 'Clothing', columns = 8:9)%>%
as_latex()%>%
write_file('tables/main-survey-results-weights-2.tex')
w10DemSpExp$mean.outcome
w10RepSpExp$mean.outcome
w35RepSpExp$mean.outcome
w35DemSpExp$mean.outcome
w39DemSpExp$mean.outcome
w39RepSpExp$mean.outcome
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7', 'Party7'
)
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7', 'Party7'
)
l = list(w10DemSpExp, w10RepSpExp, w35DemSpExp, w35RepSpExp, w39DemSpExp, w39RepSpExp)
names(l) = c('(1)', '(2)','(3)', '(4)','(5)', '(6)')
tab1 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l), fmt =3)
tab1 %>%
# column labels
tab_spanner(label = 'Neighborhood PID', columns = 2:3) %>%
tab_spanner(label = 'Contact Dem Neighbors', columns = 4) %>%
tab_spanner(label = 'Contact Rep Neighbors', columns = 5) %>%
tab_spanner(label = 'Dem - Rep Therm', columns = 6:7)
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7', 'Party7'
)
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7', 'Party7'
)
l = list(w10DemSpExp, w10RepSpExp, w35DemSpExp, w35RepSpExp, w39DemSpExp, w39RepSpExp)
names(l) = c('(1)', '(2)','(3)', '(4)','(5)', '(6)')
tab1 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l), fmt =3)
tab1 %>%
# column labels
tab_spanner(label = 'Neighborhood PID', columns = 2:3) %>%
tab_spanner(label = 'Contact Dem Neighbors', columns = 4) %>%
tab_spanner(label = 'Contact Rep Neighbors', columns = 5) %>%
tab_spanner(label = 'Dem - Rep Therm', columns = 6:7)%>%
as_latex()%>%
write_file('tables/main-survey-results-weights-1.tex')
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7', 'Party7')
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7', 'Party7')
l = list(w40DemSpExp,w40RepSpExp,w16DemSpExp,w16RepSpExp, w17DemSpExp,w17RepSpExp,w18DemSpExp,w18RepSpExp)
names(l) = c('(1)','(2)', '(3)', '(4)','(5)','(6)', '(7)', '(8)')
tab2 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l),
fmt=3)
tab2 %>%
# column labels
tab_spanner(label = 'Share PID', columns = 2:3) %>%
tab_spanner(label = 'Bumper Sticker', columns = 4:5) %>%
tab_spanner(label = 'Yard Sign', columns = 6:7) %>%
tab_spanner(label = 'Clothing', columns = 8:9)%>%
as_latex()%>%
write_file('tables/main-survey-results-weights-2.tex')
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7', 'Party7')
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7', 'Party7')
l = list(w40DemSpExp,w40RepSpExp,w16DemSpExp,w16RepSpExp, w17DemSpExp,w17RepSpExp,w18DemSpExp,w18RepSpExp)
names(l) = c('(1)','(2)', '(3)', '(4)','(5)','(6)', '(7)', '(8)')
tab2 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l),
fmt=2)
tab2 %>%
# column labels
tab_spanner(label = 'Share PID', columns = 2:3) %>%
tab_spanner(label = 'Bumper Sticker', columns = 4:5) %>%
tab_spanner(label = 'Yard Sign', columns = 6:7) %>%
tab_spanner(label = 'Clothing', columns = 8:9)%>%
as_latex()%>%
write_file('tables/main-survey-results-weights-2.tex')
w40DemSpExp$mean.outcome
w40DemSpExp$mean.outcome%>%round(2)
w40RepSpExp$mean.outcome%>%round(2)
w16DemSpExp$mean.outcome%>%round(2)
w16RepSpExp$mean.outcome%>%round(2)
w17RepSpExp$mean.outcome%>%round(2)
w17DemSpExp$mean.outcome%>%round(2)
w17DemSpExp$mean.outcome
w16DemSpExp$mean.outcome
w18DemSpExp$mean.outcome
w17DemSpExp$mean.outcome%>%round(3)
vars = c('Dem Sp Exp', 'Rep Sp Exp' ,'Dem Sp Exp * Party7','Rep Sp Exp * Party7', 'Party7')
names(vars)= c('DemSpExp', 'RepSpExp','DemSpExp:Party7', 'RepSpExp:Party7', 'Party7')
l = list(w40DemSpExp,w40RepSpExp,w16DemSpExp,w16RepSpExp, w17DemSpExp,w17RepSpExp,w18DemSpExp,w18RepSpExp)
names(l) = c('(1)','(2)', '(3)', '(4)','(5)','(6)', '(7)', '(8)')
tab2 = felm.summary.table(summaries = l,
coef_map = vars, output ='gt',
model.names=names(l),
fmt=3)
tab2 %>%
# column labels
tab_spanner(label = 'Share PID', columns = 2:3) %>%
tab_spanner(label = 'Bumper Sticker', columns = 4:5) %>%
tab_spanner(label = 'Yard Sign', columns = 6:7) %>%
tab_spanner(label = 'Clothing', columns = 8:9)%>%
as_latex()%>%
write_file('tables/main-survey-results-weights-2.tex')
w40DemSpExp$mean.outcome%>%round(3)
w40RepSpExp$mean.outcome%>%round(3)
w16RepSpExp$mean.outcome%>%round(3)
w17RepSpExp$mean.outcome%>%round(3)
w18RepSpExp$mean.outcome%>%round(3)
rm(list=ls())
library(tidyverse)
library(data.table)
library(modelsummary)
results  = read_csv('results/pid/compiled/main-results.csv')%>%
filter(Covariate %in% c('DemSpExpDiff', 'RepSpExpDiff'), grepl('pooled',file))%>%
mutate(Years=paste(Year1,Year2,sep='-'),
Subset = case_when(grepl('Dems',Model)~ 'Democrats',
grepl('Reps',Model)~'Republicans',
grepl('Oths', Model)~'Non-Partisans'),
Exposure.Type:=case_when(grepl('DemSpExp',Model)~'Democratic Exposure\non Democratic Partisanship',
grepl('RepSpExp',Model)~'Republican Exposure\non Republican Partisanship'))
colors = c(Democrats = "#377EB8",Republicans = "#E41A1C", `Non-Partisans`='purple')
g = ggplot(results, aes(x=Estimate*10, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 1)+
geom_linerange(aes(xmin=Estimate*10-1.96*SE*10, xmax=Estimate*10+1.96*SE*10),size=1)+
facet_grid(Exposure.Type~Years)+
theme_minimal()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('Effect of a 10 Percentage Point Increase in Partisan Exposure on Like-Partisanship')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
g
results
ggplot(results, aes(x=Estimate*10, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 1)+
geom_linerange(aes(xmin=Estimate*10-1.96*SE*10, xmax=Estimate*10+1.96*SE*10),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('Effect of a 10 Percentage Point Increase in Partisan Exposure on Like-Partisanship')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
g = ggplot(results, aes(x=Estimate*10, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate*10-1.96*SE*10, xmax=Estimate*10+1.96*SE*10),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('Effect of a 10 Percentage Point Increase in Partisan Exposure on Like-Partisanship')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
g
ggplot(results, aes(x=Estimate*10, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 3)+
geom_linerange(aes(xmin=Estimate*10-1.96*SE*10, xmax=Estimate*10+1.96*SE*10),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('Effect of a 10 Percentage Point Increase in Partisan Exposure on Like-Partisanship')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 3)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('Effect of a 10 Percentage Point Increase in Partisan Exposure on Like-Partisanship')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 3)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
results[Years=='2012-2016',Estimate=Estimate*100]
names(results)
results=as.data.table(reesults)
results=as.data.table(results)
results[Years=='2012-2016',Estimate=Estimate*100]
results[Years=='2012-2016',Estimate:=Estimate*100]
results[Years=='2012-2016',SE:=SE*100]
ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=15,family="serif"))
ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=24,family="serif"))
results  = read_csv('results/pid/compiled/main-results.csv')%>%
filter(Covariate %in% c('DemSpExpDiff', 'RepSpExpDiff'), grepl('pooled',file))%>%
mutate(Years=paste(Year1,Year2,sep='-'),
Subset = case_when(grepl('Dems',Model)~ 'Democrats',
grepl('Reps',Model)~'Republicans',
grepl('Oths', Model)~'Non-Partisans'),
Exposure.Type:=case_when(grepl('DemSpExp',Model)~'Dem. Exp.\non Dem. Reg.',
grepl('RepSpExp',Model)~'Rep. Exp.\non Rep. Reg.'))
colors = c(Democrats = "#377EB8",Republicans = "#E41A1C", `Non-Partisans`='purple')
g = ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=24,family="serif"))
g
rm(list=ls())
library(tidyverse)
library(data.table)
library(modelsummary)
results  = read_csv('results/pid/compiled/main-results.csv')%>%
filter(Covariate %in% c('DemSpExpDiff', 'RepSpExpDiff'), grepl('pooled',file))%>%
mutate(Years=paste(Year1,Year2,sep='-'),
Subset = case_when(grepl('Dems',Model)~ 'Democrats',
grepl('Reps',Model)~'Republicans',
grepl('Oths', Model)~'Non-Partisans'),
Exposure.Type:=case_when(grepl('DemSpExp',Model)~'Dem. Exp.\non Dem. Reg.',
grepl('RepSpExp',Model)~'Rep. Exp.\non Rep. Reg.'))
colors = c(Democrats = "#377EB8",Republicans = "#E41A1C", `Non-Partisans`='purple')
g = ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 4)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=24,family="serif"))
g
source('~/Research_Group Dropbox/Jacob Brown/dissertation/jmp/code/make-main-results.R', echo=TRUE)
source('~/Research_Group Dropbox/Jacob Brown/dissertation/jmp/code/make-main-results.R', echo=TRUE)
g = ggplot(results, aes(x=Estimate, y = Subset, color = Subset, fill = Subset, shape = Subset))+
geom_point(size = 5)+
geom_linerange(aes(xmin=Estimate-1.96*SE, xmax=Estimate+1.96*SE),size=1)+
facet_grid(Exposure.Type~Years)+
theme_bw()+
geom_vline(xintercept= 0, linetype='dashed')+
scale_fill_manual(values=colors)+
scale_color_manual(values=colors)+
xlab('')+
ylab('Original Partisanship')+
guides(shape='none',color='none',fill='none')+
theme(text=element_text(size=24,family="serif"))
ggsave(filename = 'graphics/main-results.png',plot =g, width=11,height=6,units='in')
source('~/Research_Group Dropbox/Jacob Brown/dissertation/jmp/code/make-main-results.R', echo=TRUE)
setwd("~/Research_Group Dropbox/Jacob Brown/partisan_segregation/replication_file_old")
##
rm(list = ls())
library(readr)
library(tidyr)
library(dplyr)
library(ggplot2)
library(cowplot)
library(pscl, quietly = T) # IRT models
library(Hmisc)
library(ggpubr)
# In this script we compare ideology of imputated versus non-imputed and output Figure S23, S24, and S25
## Load in data
dat = read_csv('data/partisan-survey-analysis.csv')
# Set ideology levels
ideology.levels = c('Extremely Liberal','Liberal','Slightly Liberal','Moderate; middle of the road',
'Slightly Conservative','Conservative','Extremely Conservative')
interest.levels = c('Not at all interested','Not very interested','Somewhat interested','Very Interested')
discuss.levels = c("Never or close to never","Just a few times a year","About once a month",
"About once a week, but not every day","Nearly every day")
## recode variables and filter sample to respondents who verify their identity
dat = dat%>%
mutate(imputed = ifelse(L2_recorded_pid == 'i',1,0),
L2_recorded_pid = recode(L2_recorded_pid, "d" = "Democrat","r"= "Republican","i" = "Independent"),
self_ideology = factor(self_ideology,levels = ideology.levels),
ideology_numeric = recode(self_ideology,'Extremely Liberal'=1,
'Liberal'=2,
'Slightly Liberal'=3,
'Moderate; middle of the road'=4,
'Slightly Conservative'=5,
'Conservative'=6,
'Extremely Conservative' = 7),
interest = factor(interest,levels = interest.levels),
high_interest = ifelse(interest == 'Very Interested',1,0),
discuss = factor(discuss, levels = discuss.levels),
impute_state = ifelse(L2_state_record_pid==1&imputed==1,'State PID/ Imputed',
ifelse(L2_state_record_pid==1&imputed==0,'State PID/ Not Imputed',
ifelse(L2_state_record_pid==0&imputed==1,'State No PID/ Imputed',
'State No PID/ Not Imputed'))),
imputed_text = ifelse(imputed == 1, "Imputed", "Not Imputed"),
all_party = ifelse(imputed == 1, party_3,L2_recorded_pid)) %>% ##imputed and self reported party
filter(self == 'Yes')
## Load custom ggplot themes
source('code/theme_jake.R')
############
ideology.plot.party = ggplot(data = dat%>%
filter(is.na(self_ideology)==F&is.na(party_3)==F&party_3%in%c('Democrat','Republican')),
aes(x = self_ideology))+
geom_bar(aes(y = (..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..])) +
scale_y_continuous(name="Percent") +
theme_jake()+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
axis.title.x = element_blank()) +
facet_wrap(party_3~imputed_text,ncol=2)
ideology.plot.party
ideology.plot.party.state = ggplot(data = dat%>%
filter(is.na(self_ideology)==F&is.na(party_3)==F&party_3%in%c('Democrat','Republican')),
aes(x = self_ideology))+
geom_bar(aes(y = (..count..)/tapply(..count..,..PANEL..,sum)[..PANEL..])) +
scale_y_continuous(name="Percent") +
theme_jake()+
theme(axis.text.x = element_text(angle = 45, hjust = 1),
axis.title.x = element_blank(),
plot.title = element_text(size = 24)) +
facet_wrap(party_3~impute_state)
ideology.plot.party.state
##what about policy positions?
# rollcall matrix, cols are different policy variables
rollcall_mat <- dat%>%
select("Cong_Affordable","Cong_Health","Cong_Choice","Cong_Kate","Cong_Countering",
"Cong_Sanctuary","Cong_assault","Cong_impeach","Cong_pay")
# create rollcall object
rc <- rollcall(rollcall_mat, yea = "For", nay = "Against",
legis.names = dat$ResponseId,
vote.names = c("Cong_Affordable","Cong_Health","Cong_Choice","Cong_Kate","Cong_Countering",
"Cong_Sanctuary","Cong_assault","Cong_impeach","Cong_pay"))
# create IRT model
ideals <- ideal(rc, normalize = T)
# show distribution if ideal points
plot.ideal(ideals)
ideals.dat = data.frame(ResponseId = labels(ideals$xbar)[[1]], ideals = as.numeric(ideals$xbar))
dat = left_join(dat,ideals.dat)
dat = dat%>%
mutate(r.post.bin = cut_number(L2_pos.imp.r,n = 5),
d.post.bin = cut_number(L2_pos.imp.d,n = 5),
ideals = ideals*-1)
axis.size = 7
label.size = 9
library(RColorBrewer)
colors = brewer.pal(3,"Accent")[1:3]
ideology.plot.binned.all = ggplot(data = dat%>%
filter(is.na(r.post.bin)==F),
aes(y = ideology_numeric,x =d.post.bin))+
stat_summary(fun.y='mean',aes(group = impute_state,color = impute_state),
geom="point",
position = position_dodge(.75), size = 5)+
scale_color_manual(values = colors) +
guides(fill = FALSE,color=guide_legend("Imputation"))+
geom_boxplot(aes(fill = impute_state),
alpha = .5)+
scale_fill_manual(values = colors) +
theme_jake() +
theme(legend.position="right")+
scale_y_continuous(name = 'Self-reported Ideology')+
scale_x_discrete(name = 'Pr(D)')
ideology.plot.continuous.all = ggplot(data = dat%>%filter(is.na(self_ideology)==F),
aes(y = ideals,x = L2_pos.imp.d,
color = impute_state))+
geom_point(alpha = 0.2) +
geom_smooth(method = "loess", size = 1.5)+
scale_color_manual(values = colors) +
theme_jake()+
theme(legend.position="right")+
guides(color=guide_legend("Imputation"))+
scale_y_continuous(name = 'Issue-scaled Ideology')+
scale_x_continuous(name = 'Pr(D)')
out.grid = ggarrange(ideology.plot.binned.all,ideology.plot.continuous.all,
nrow=2,
ncol = 1,
common.legend = TRUE, legend="bottom")
out.grid
load("~/Research_Group Dropbox/Jacob Brown/partisan_segregation/data/relative-exposure-aggregate-data.Rdata")
head(cbsa)
length(unique(cbsa$cbsacode))
length(unique(cbsa$cbsatitle))
library(spatstat)
runif(0,1,4)
runif(0,1,4)
runif(4,0,1)
round(runif(4,0,1),2)
library(tidyverse)
library(knitr)
library(kableExtra)
tibble(`Voter ID` = 1:4, `Voter PID` = c('D','R','D','R'),`Precinct %Dem` = round(runif(4,0,1),2), `Vote 2020` = c('Yes', 'Yes', 'Yes','No'))%>%
kable
library(tidyverse)
library(knitr)
library(kableExtra)
tibble(`Voter ID` = 1:4, `Voter PID` = c('D','R','D','R'),`Precinct %Dem` = round(runif(4,0,1),2), `Vote 2020` = c('Yes', 'Yes', 'Yes','No'))%>%
gt
load("~/Research_Group Dropbox/Jacob Brown/partisan_segregation/official_replication_file/data/relative-exposure-aggregate-date.Rdata")
zip
setwd("~/Research_Group Dropbox/Jacob Brown/partisan_segregation/official_replication_file")
survey = read_csv('data/partisan-survey-analysis.csv')
names(survey)
source('~/Research_Group Dropbox/Jacob Brown/partisan_segregation/official_replication_file/code/FigE5_FigS3_FigS20_FigS21_FigS22_TabS6_TabS7_TabS8_TabS9_TabS10_TabS11.R', echo=TRUE)
source('~/Research_Group Dropbox/Jacob Brown/partisan_segregation/official_replication_file/code/FigE5_FigS3_FigS20_FigS21_FigS22_TabS6_TabS7_TabS8_TabS9_TabS10_TabS11.R', echo=TRUE)
